; ModuleID = 'get_data.c'
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
target triple = "i386-pc-linux-gnu"

%struct.MPI_Status = type { i32, i32, i32, i32, i32 }
%struct.ompi_communicator_t = type opaque
%struct.ompi_datatype_t = type opaque
%struct.ompi_predefined_communicator_t = type opaque
%struct.ompi_predefined_datatype_t = type opaque

@ompi_mpi_comm_world = external global %struct.ompi_predefined_communicator_t
@ompi_mpi_float = external global %struct.ompi_predefined_datatype_t
@.str = private constant [38 x i8] c"With n = %d trapezoids, our estimate\0A\00", align 4
@.str1 = private constant [36 x i8] c"of the integral from %f to %f = %f\0A\00", align 4
@.str2 = private constant [18 x i8] c"Enter a, b, and n\00", align 1
@.str3 = private constant [9 x i8] c"%f %f %d\00", align 1
@ompi_mpi_int = external global %struct.ompi_predefined_datatype_t

define i32 @main(i32 %argc, i8** %argv) nounwind {
entry:
  %argc_addr = alloca i32, align 4
  %argv_addr = alloca i8**, align 4
  %retval = alloca i32
  %my_rank = alloca i32
  %p = alloca i32
  %a = alloca float
  %b = alloca float
  %n = alloca i32
  %h = alloca float
  %local_a = alloca float
  %local_b = alloca float
  %local_n = alloca i32
  %integral = alloca float
  %total = alloca float
  %source = alloca i32
  %dest = alloca i32
  %tag = alloca i32
  %status = alloca %struct.MPI_Status
  %"alloca point" = bitcast i32 0 to i32
  store i32 %argc, i32* %argc_addr
  store i8** %argv, i8*** %argv_addr
  store i32 0, i32* %dest, align 4
  store i32 0, i32* %tag, align 4
  %0 = call i32 @MPI_Init(i32* %argc_addr, i8*** %argv_addr) nounwind
  %1 = call i32 @MPI_Comm_rank(%struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*), i32* %my_rank) nounwind
  %2 = call i32 @MPI_Comm_size(%struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*), i32* %p) nounwind
  %3 = load i32* %p, align 4
  %4 = load i32* %my_rank, align 4
  call void @Get_data(float* %a, float* %b, i32* %n, i32 %4, i32 %3) nounwind
  %5 = load float* %b, align 4
  %6 = load float* %a, align 4
  %7 = fsub float %5, %6
  %8 = load i32* %n, align 4
  %9 = sitofp i32 %8 to float
  %10 = fdiv float %7, %9
  store float %10, float* %h, align 4
  %11 = load i32* %n, align 4
  %12 = load i32* %p, align 4
  %13 = sdiv i32 %11, %12
  store i32 %13, i32* %local_n, align 4
  %14 = load i32* %my_rank, align 4
  %15 = load i32* %local_n, align 4
  %16 = mul nsw i32 %14, %15
  %17 = sitofp i32 %16 to float
  %18 = load float* %h, align 4
  %19 = fmul float %17, %18
  %20 = load float* %a, align 4
  %21 = fadd float %19, %20
  store float %21, float* %local_a, align 4
  %22 = load i32* %local_n, align 4
  %23 = sitofp i32 %22 to float
  %24 = load float* %h, align 4
  %25 = fmul float %23, %24
  %26 = load float* %local_a, align 4
  %27 = fadd float %25, %26
  store float %27, float* %local_b, align 4
  %28 = load float* %local_a, align 4
  %29 = load float* %local_b, align 4
  %30 = load i32* %local_n, align 4
  %31 = load float* %h, align 4
  %32 = call float @Trap(float %28, float %29, i32 %30, float %31) nounwind
  store float %32, float* %integral, align 4
  %33 = load i32* %my_rank, align 4
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %bb, label %bb5

bb:                                               ; preds = %entry
  %35 = load float* %integral, align 4
  store float %35, float* %total, align 4
  store i32 1, i32* %source, align 4
  br label %bb3

bb1:                                              ; preds = %bb3
  %integral2 = bitcast float* %integral to i8*
  %36 = load i32* %source, align 4
  %37 = load i32* %tag, align 4
  %38 = call i32 @MPI_Recv(i8* %integral2, i32 1, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_float to %struct.ompi_datatype_t*), i32 %36, i32 %37, %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*), %struct.MPI_Status* %status) nounwind
  %39 = load float* %integral, align 4
  %40 = load float* %total, align 4
  %41 = fadd float %40, %39
  store float %41, float* %total, align 4
  %42 = load i32* %source, align 4
  %43 = add nsw i32 %42, 1
  store i32 %43, i32* %source, align 4
  br label %bb3

bb3:                                              ; preds = %bb1, %bb
  %44 = load i32* %p, align 4
  %45 = load i32* %source, align 4
  %46 = icmp slt i32 %45, %44
  br i1 %46, label %bb1, label %bb4

bb4:                                              ; preds = %bb3
  br label %bb7

bb5:                                              ; preds = %entry
  %integral6 = bitcast float* %integral to i8*
  %47 = load i32* %dest, align 4
  %48 = load i32* %tag, align 4
  %49 = call i32 @MPI_Send(i8* %integral6, i32 1, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_float to %struct.ompi_datatype_t*), i32 %47, i32 %48, %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*)) nounwind
  br label %bb7

bb7:                                              ; preds = %bb5, %bb4
  %50 = load i32* %my_rank, align 4
  %51 = icmp eq i32 %50, 0
  br i1 %51, label %bb8, label %bb9

bb8:                                              ; preds = %bb7
  %52 = load i32* %n, align 4
  %53 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([38 x i8]* @.str, i32 0, i32 0), i32 %52) nounwind
  %54 = load float* %total, align 4
  %55 = fpext float %54 to double
  %56 = load float* %b, align 4
  %57 = fpext float %56 to double
  %58 = load float* %a, align 4
  %59 = fpext float %58 to double
  %60 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([36 x i8]* @.str1, i32 0, i32 0), double %59, double %57, double %55) nounwind
  br label %bb9

bb9:                                              ; preds = %bb8, %bb7
  %61 = call i32 @MPI_Finalize() nounwind
  br label %return

return:                                           ; preds = %bb9
  %retval10 = load i32* %retval
  ret i32 %retval10
}

declare i32 @MPI_Init(i32*, i8***)

declare i32 @MPI_Comm_rank(%struct.ompi_communicator_t*, i32*)

declare i32 @MPI_Comm_size(%struct.ompi_communicator_t*, i32*)

declare i32 @MPI_Recv(i8*, i32, %struct.ompi_datatype_t*, i32, i32, %struct.ompi_communicator_t*, %struct.MPI_Status*)

declare i32 @MPI_Send(i8*, i32, %struct.ompi_datatype_t*, i32, i32, %struct.ompi_communicator_t*)

declare i32 @printf(i8* noalias, ...) nounwind

declare i32 @MPI_Finalize()

define void @Get_data(float* %a_ptr, float* %b_ptr, i32* %n_ptr, i32 %my_rank, i32 %p) nounwind {
entry:
  %a_ptr_addr = alloca float*, align 4
  %b_ptr_addr = alloca float*, align 4
  %n_ptr_addr = alloca i32*, align 4
  %my_rank_addr = alloca i32, align 4
  %p_addr = alloca i32, align 4
  %source = alloca i32
  %dest = alloca i32
  %tag = alloca i32
  %status = alloca %struct.MPI_Status
  %"alloca point" = bitcast i32 0 to i32
  store float* %a_ptr, float** %a_ptr_addr
  store float* %b_ptr, float** %b_ptr_addr
  store i32* %n_ptr, i32** %n_ptr_addr
  store i32 %my_rank, i32* %my_rank_addr
  store i32 %p, i32* %p_addr
  store i32 0, i32* %source, align 4
  %0 = load i32* %my_rank_addr, align 4
  %1 = icmp eq i32 %0, 0
  br i1 %1, label %bb, label %bb4

bb:                                               ; preds = %entry
  %2 = call i32 @puts(i8* getelementptr inbounds ([18 x i8]* @.str2, i32 0, i32 0)) nounwind
  %3 = load float** %a_ptr_addr, align 4
  %4 = load float** %b_ptr_addr, align 4
  %5 = load i32** %n_ptr_addr, align 4
  %6 = call i32 (i8*, ...)* @"\01__isoc99_scanf"(i8* noalias getelementptr inbounds ([9 x i8]* @.str3, i32 0, i32 0), float* %3, float* %4, i32* %5) nounwind
  store i32 1, i32* %dest, align 4
  br label %bb2

bb1:                                              ; preds = %bb2
  store i32 0, i32* %tag, align 4
  %7 = load float** %a_ptr_addr, align 4
  %8 = bitcast float* %7 to i8*
  %9 = load i32* %dest, align 4
  %10 = load i32* %tag, align 4
  %11 = call i32 @MPI_Send(i8* %8, i32 1, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_float to %struct.ompi_datatype_t*), i32 %9, i32 %10, %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*)) nounwind
  store i32 1, i32* %tag, align 4
  %12 = load float** %b_ptr_addr, align 4
  %13 = bitcast float* %12 to i8*
  %14 = load i32* %dest, align 4
  %15 = load i32* %tag, align 4
  %16 = call i32 @MPI_Send(i8* %13, i32 1, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_float to %struct.ompi_datatype_t*), i32 %14, i32 %15, %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*)) nounwind
  store i32 2, i32* %tag, align 4
  %17 = load i32** %n_ptr_addr, align 4
  %18 = bitcast i32* %17 to i8*
  %19 = load i32* %dest, align 4
  %20 = load i32* %tag, align 4
  %21 = call i32 @MPI_Send(i8* %18, i32 1, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_int to %struct.ompi_datatype_t*), i32 %19, i32 %20, %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*)) nounwind
  %22 = load i32* %dest, align 4
  %23 = add nsw i32 %22, 1
  store i32 %23, i32* %dest, align 4
  br label %bb2

bb2:                                              ; preds = %bb1, %bb
  %24 = load i32* %dest, align 4
  %25 = load i32* %p_addr, align 4
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %bb1, label %bb3

bb3:                                              ; preds = %bb2
  br label %bb5

bb4:                                              ; preds = %entry
  store i32 0, i32* %tag, align 4
  %27 = load float** %a_ptr_addr, align 4
  %28 = bitcast float* %27 to i8*
  %29 = load i32* %source, align 4
  %30 = load i32* %tag, align 4
  %31 = call i32 @MPI_Recv(i8* %28, i32 1, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_float to %struct.ompi_datatype_t*), i32 %29, i32 %30, %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*), %struct.MPI_Status* %status) nounwind
  store i32 1, i32* %tag, align 4
  %32 = load float** %b_ptr_addr, align 4
  %33 = bitcast float* %32 to i8*
  %34 = load i32* %source, align 4
  %35 = load i32* %tag, align 4
  %36 = call i32 @MPI_Recv(i8* %33, i32 1, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_float to %struct.ompi_datatype_t*), i32 %34, i32 %35, %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*), %struct.MPI_Status* %status) nounwind
  store i32 2, i32* %tag, align 4
  %37 = load i32** %n_ptr_addr, align 4
  %38 = bitcast i32* %37 to i8*
  %39 = load i32* %source, align 4
  %40 = load i32* %tag, align 4
  %41 = call i32 @MPI_Recv(i8* %38, i32 1, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_int to %struct.ompi_datatype_t*), i32 %39, i32 %40, %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*), %struct.MPI_Status* %status) nounwind
  br label %bb5

bb5:                                              ; preds = %bb4, %bb3
  br label %return

return:                                           ; preds = %bb5
  ret void
}

declare i32 @puts(i8*)

declare i32 @"\01__isoc99_scanf"(i8* noalias, ...) nounwind

define float @Trap(float %local_a, float %local_b, i32 %local_n, float %h) nounwind {
entry:
  %local_a_addr = alloca float, align 4
  %local_b_addr = alloca float, align 4
  %local_n_addr = alloca i32, align 4
  %h_addr = alloca float, align 4
  %retval = alloca float
  %0 = alloca float
  %integral = alloca float
  %x = alloca float
  %i = alloca i32
  %"alloca point" = bitcast i32 0 to i32
  store float %local_a, float* %local_a_addr
  store float %local_b, float* %local_b_addr
  store i32 %local_n, i32* %local_n_addr
  store float %h, float* %h_addr
  %1 = load float* %local_a_addr, align 4
  %2 = call float @f(float %1) nounwind
  %3 = load float* %local_b_addr, align 4
  %4 = call float @f(float %3) nounwind
  %5 = fadd float %2, %4
  %6 = fdiv float %5, 2.000000e+00
  store float %6, float* %integral, align 4
  %7 = load float* %local_a_addr, align 4
  store float %7, float* %x, align 4
  store i32 1, i32* %i, align 4
  br label %bb1

bb:                                               ; preds = %bb1
  %8 = load float* %x, align 4
  %9 = load float* %h_addr, align 4
  %10 = fadd float %8, %9
  store float %10, float* %x, align 4
  %11 = load float* %x, align 4
  %12 = call float @f(float %11) nounwind
  %13 = load float* %integral, align 4
  %14 = fadd float %12, %13
  store float %14, float* %integral, align 4
  %15 = load i32* %i, align 4
  %16 = add nsw i32 %15, 1
  store i32 %16, i32* %i, align 4
  br label %bb1

bb1:                                              ; preds = %bb, %entry
  %17 = load i32* %local_n_addr, align 4
  %18 = sub nsw i32 %17, 1
  %19 = load i32* %i, align 4
  %20 = icmp sge i32 %18, %19
  br i1 %20, label %bb, label %bb2

bb2:                                              ; preds = %bb1
  %21 = load float* %integral, align 4
  %22 = load float* %h_addr, align 4
  %23 = fmul float %21, %22
  store float %23, float* %integral, align 4
  %24 = load float* %integral, align 4
  store float %24, float* %0, align 4
  %25 = load float* %0, align 4
  store float %25, float* %retval, align 4
  br label %return

return:                                           ; preds = %bb2
  %retval3 = load float* %retval
  ret float %retval3
}

define float @f(float %x) nounwind {
entry:
  %x_addr = alloca float, align 4
  %retval = alloca float
  %0 = alloca float
  %return_val = alloca float
  %"alloca point" = bitcast i32 0 to i32
  store float %x, float* %x_addr
  %1 = load float* %x_addr, align 4
  %2 = load float* %x_addr, align 4
  %3 = fmul float %1, %2
  store float %3, float* %return_val, align 4
  %4 = load float* %return_val, align 4
  store float %4, float* %0, align 4
  %5 = load float* %0, align 4
  store float %5, float* %retval, align 4
  br label %return

return:                                           ; preds = %entry
  %retval1 = load float* %retval
  ret float %retval1
}
